package io.bsly.modules.app.service.localmaster.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.bsly.common.utils.PageUtils;
import io.bsly.common.utils.Query;
import io.bsly.modules.app.dao.localDao.DyProductDao;
import io.bsly.modules.app.entity.localEntity.DyProductEntity;
import io.bsly.modules.app.service.localmaster.DyProductService;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("dyProductService")
public class DyProductServiceImpl extends ServiceImpl<DyProductDao, DyProductEntity> implements DyProductService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        LambdaQueryWrapper<DyProductEntity> queryWrapper = new QueryWrapper<DyProductEntity>().lambda()
                .like(params.containsKey("name") && ObjectUtil.isNotNull(params.get("name")), DyProductEntity::getName, params.get("name"))
                .like(params.containsKey("city") && ObjectUtil.isNotNull(params.get("city")), DyProductEntity::getCity, params.get("city"));

        if (params.containsKey("status") && ObjectUtil.isNotNull(params.get("status"))){
            queryWrapper.eq(DyProductEntity::getStatus,Integer.parseInt(params.get("status").toString()));
        }
        IPage<DyProductEntity> page = this.page(  new Query<DyProductEntity>().getPage(params), queryWrapper );
        return new PageUtils(page);
    }

}